package cn.com.dhcc.adam.spring.spel;

import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

public class SpELParser {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		test1();
		test2();
		test3();
		test4();
		test5();
	}

	static final public void test1() {
		ExpressionParser parser = new SpelExpressionParser();
		Expression exp = parser.parseExpression("'Hello World'");
		String message = (String) exp.getValue();
		System.out.println(message);
	}

	/**
	 * 
	 */
	static final public void test2() {
		ExpressionParser parser = new SpelExpressionParser();
		Expression exp = parser.parseExpression("'Hello World'.concat('!')");
		String message = (String) exp.getValue();
		System.out.println(message);
	}

	/**
	 * 
	 */
	static final public void test3() {
		ExpressionParser parser = new SpelExpressionParser();
		// invokes getBytes().length
		Expression exp = parser.parseExpression("'Hello World'.bytes.length");
		int length = (Integer) exp.getValue();
		System.out.println(length);
	}

	static final public void test4() {
		ExpressionParser paser = new SpelExpressionParser();
		Expression ex = paser
				.parseExpression("new String('Hello cedo').toUpperCase()");
		String message = (String) ex.getValue();
		System.out.println(message);
	}

	static final public void test5() {
		ExpressionParser paser = new SpelExpressionParser();
		Expression ex = paser
				.parseExpression("new String('Hello cedo').toUpperCase()");
		String message = ex.getValue(String.class);
		System.out.println(message);
	}

	static final public void test6() {
		
	}
}
